<template>
	<view class="jishuqi">


		<view class="one">
			<view @click="reduce" class="reduce">
				<image src="/static/excharge/1_6_2.png"></image>
			</view>
			<view>{{num}}</view>
			<view @click="add" class="add">
				<image src="/static/excharge/1_6_1.png"></image>
			</view>
		</view>

		<view class="two">
			<image src="/static/excharge/1_7.png" @click="add"></image>
		</view>



	</view>
</template>

<script>
	import {mapGetters, mapState} from 'vuex'
	export default {
		name: "jishuqi",
		props: ['excharge','stock'],
		data() {
			return {
				num: 0
			};
		},
		computed: {
			...mapGetters(['totalPrice','userScore'])
		},
		methods: {
			// 增加数量
			add() {
				//增加数量要满足 库存够，且当前
				if(this.num < this.stock && this.totalPrice + this.excharge <= this.userScore){
					this.num += 1
					this.count()
				}else if(this.num >= this.stock){
					console.log('is defeat')
					this.$emit('defeat')
				}else if(this.totalPrice + this.excharge > this.userScore){
					console.log('is noscore')
					this.$emit('noscore')
				}
			},
			// 减少数量
			reduce() {
				if(this.num > 0){
					this.num -= 1
					this.count()
				}
			},
			
			// 计算
			count() {
				this.$emit('modify', this.num)
			},
			reset(){
				this.num = 0
			}
		}
	}
</script>

<style>
	.jishuqi {
		margin: 0 auto;
		width: 250rpx;
		height: 80rpx;
		border-radius: 10rpx;
		display: flex;
		justify-content: space-around;
		align-items: center;
	}

	#jishuqi view {
		display: inline-block;
	}

	.jishuqi .one {
		width: 170rpx;
		height: 40rpx;
		border-radius: 5rpx;
		margin-left: 15rpx;
		border: 1px rgba(197, 202, 211, 0.3) solid;
	}

	.jishuqi .one view {
		/* border: 1rpx rgba(197, 202, 211, 0.3) solid; */
		position: relative;
		top: -1px;
		color: white;
		display: inline-block;
		width: 40rpx;
		height: 40rpx;
		line-height: 40rpx;
	}
	
	.jishuqi .one view:nth-child(1) {
		border-right: 1px rgba(197, 202, 211, 0.3) solid;;
	}
	.jishuqi .one view:nth-child(3) {
		border-left: 1px rgba(197, 202, 211, 0.3) solid;;
	}

	.jishuqi .two {
		position: relative;
		top: -10rpx;
		left: 10rpx;
		width: 130rpx;
		height: 50rpx;
		margin-top: 25rpx;
		text-align: right;
	}

	.jishuqi .two > image {
		width: 73rpx;
		height: 47rpx;
		text-align: right;
	}

	.reduce > image {
		position: relative;
		top: -10rpx;
		width: 18rpx;
		height: 3rpx;
	}

	.add > image {
		position: relative;
		top: -2rpx;
		width: 18rpx;
		height: 18rpx;
	}
</style>
